import random, threading

class Node(object):       
    def __init__(self, host_port, public_key):
        self.host_port = host_port
        self.public_key = public_key

class Crowd(object):
    __members = {}    
    lock = threading.RLock()
        
    def update_member_list(self, members):
        for jondo in members:
            ip = jondo.host_port[0]
            self.__members[ip] = jondo
        
    def pick_random_jondo(self):
        if self.__members:
            jondo = random.sample(self.__members.values(), 1)
            return jondo[0]
        else:
            return None
        
    def check_jondo(self, ip):
        """
        must find a way to check if connecting jondo is allowed to comunicate 
        """
        #return ip in self.__members
        return 1
        
    
    def get_jondos(self):
        return self.__members.values()
    

        